package com.framework.boc.admin.controller;

import com.framework.boc.admin.entity.ErrorMessage;
import com.framework.boc.admin.entity.Material;
import com.framework.boc.admin.entity.ResponseMessage;
import com.framework.boc.admin.entity.Result;
import com.framework.boc.response.CommonResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.json.JsonParser;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/contract")
public class ContractController {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @GetMapping("/verify")
    public CommonResponse verifyContract(@RequestParam("phoneNum") String phoneNum) {
        boolean verifyRes = true;
        return CommonResponse.success(verifyRes);
    }

    @PostMapping("/material-list")
    public CommonResponse queryMaterial(@RequestBody String vbillcode) {
        logger.info("vbillcode===========" + vbillcode);
        /*todo
         * 调用销售合同详细信息查询接口
         */

        //测试数据
        Material material = new Material();
        List<Material> bodys = new ArrayList<>();
        Result res = new Result();
        List<Result> result = new ArrayList<>();
        ErrorMessage errorMessage = new ErrorMessage();
        ResponseMessage responseMessage = new ResponseMessage();
        responseMessage.setState("0");
        responseMessage.setContent("成功");
        responseMessage.setErrorMessage(errorMessage);

        material.setBodyid("10001");
        material.setHeadid("2300001");
        material.setMaterialcode("800001");
        material.setMaterialname("疯牛病疫苗");
        material.setMaterialspec("大包装");
        material.setMaterialtype("1号");
        material.setCunitid("支");
        material.setNprice(6689);
        bodys.add(material);

        Material material1 = new Material();
        material1.setBodyid("10002");
        material1.setHeadid("2300001");
        material1.setMaterialcode("800002");
        material1.setMaterialname("疯牛病疫苗");
        material1.setMaterialspec("中包装");
        material1.setMaterialtype("2号");
        material1.setCunitid("支");
        material1.setNprice(4689);
        bodys.add(material1);

        Material material2 = new Material();
        material2.setBodyid("10003");
        material2.setHeadid("2300001");
        material2.setMaterialcode("800003");
        material2.setMaterialname("疯牛病疫苗");
        material2.setMaterialspec("小包装");
        material2.setMaterialtype("3号");
        material2.setCunitid("支");
        material2.setNprice(2689);
        bodys.add(material2);

        res.setHeadid("2300001");
        res.setOrgcode("600001");
        res.setOrgname("蒙牛集团");
        res.setVbillcode("680001");
        res.setCtname("疯牛病疫苗合同");
        res.setCustcode("10001");
        res.setCustname("张三");
        res.setMobile("13789826732");
        res.setSubscribedate("20200520");
        res.setValdate("20200521");
        res.setInvalidate("20220520");
        res.setBodys(bodys);

        result.add(res);
        /*****************************************************/

        List<Material> bodys2 = new ArrayList<>();
        Material material3 = new Material();
        material3.setBodyid("20001");
        material3.setHeadid("2300002");
        material3.setMaterialcode("810001");
        material3.setMaterialname("禽流感疫苗");
        material3.setMaterialspec("大包装");
        material3.setMaterialtype("1号");
        material3.setCunitid("支");
        material3.setNprice(10989);
        bodys2.add(material3);

        Material material4 = new Material();
        material4.setBodyid("20002");
        material4.setHeadid("2300002");
        material4.setMaterialcode("810002");
        material4.setMaterialname("禽流感疫苗");
        material4.setMaterialspec("中包装");
        material4.setMaterialtype("2号");
        material4.setCunitid("支");
        material4.setNprice(12989);
        bodys2.add(material4);

        Material material5 = new Material();
        material5.setBodyid("20003");
        material5.setHeadid("2300002");
        material5.setMaterialcode("810003");
        material5.setMaterialname("禽流感疫苗");
        material5.setMaterialspec("小包装");
        material5.setMaterialtype("3号");
        material5.setCunitid("支");
        material5.setNprice(16989);
        bodys2.add(material5);

        Result res1 = new Result();
        res1.setHeadid("2300002");
        res1.setOrgcode("600002");
        res1.setOrgname("金宇集团");
        res1.setVbillcode("680002");
        res1.setCtname("禽流感疫苗合同");
        res1.setCustcode("10002");
        res1.setCustname("李四");
        res1.setMobile("13789826345");
        res1.setSubscribedate("20200720");
        res1.setValdate("20200721");
        res1.setInvalidate("20240520");
        res1.setBodys(bodys2);

        result.add(res1);
        /*****************************************************/

        responseMessage.setResult(result);

        return CommonResponse.success(responseMessage);
    }

    @PostMapping("/contract-list")
    public CommonResponse queryContract(@RequestBody String cond) {
        logger.info("cond===========" + cond);

        /*todo
         * 调用销售合同信息查询接口
         */

        //测试数据
        Result res = new Result();
        List<Result> result = new ArrayList<>();
        ErrorMessage errorMessage = new ErrorMessage();
        ResponseMessage responseMessage = new ResponseMessage();
        responseMessage.setState("0");
        responseMessage.setContent("成功");
        responseMessage.setErrorMessage(errorMessage);

        res.setHeadid("2300001");
        res.setVbillcode("680001");
        res.setCtname("疯牛病疫苗合同");
        res.setCustcode("10001");
        res.setCustname("张三");
        res.setMobile("13789826345");
        result.add(res);

        Result res1 = new Result();
        res1.setHeadid("2300002");
        res1.setVbillcode("680002");
        res1.setCtname("禽流感疫苗合同");
        res1.setCustcode("10002");
        res1.setCustname("李四");
        res1.setMobile("13789826345");
        result.add(res1);

        Result res2 = new Result();
        res2.setHeadid("2300003");
        res2.setVbillcode("680003");
        res2.setCtname("口蹄疫疫苗合同");
        res2.setCustcode("10003");
        res2.setCustname("王五");
        res2.setMobile("13789826345");
        result.add(res2);

        responseMessage.setResult(result);
        return CommonResponse.success(responseMessage);
    }
}
